Unity3d and SQLite database Part 2

Click Here to View Step by Step

How to read data from on unity

Solving all error in unity for assembly reference:

1- error "The type or namespace name Data' does not exist in the namespace 'Mono'. Are you missing an assembly reference?"

2- and error "The type or namespace name MONO' does not exist in the namespace Data'. Are you missing an assembly reference?"

Notes:

1- SQLite supported and working on windows 7 32bit and 64bit

2- SQLite supported and working on visual studio 2010

3- SQLite supported and working with .Net Framework 2.0

learning how:

* SQLite Admin to create database and tables .......

* SQLite DLL to support unity .s3db extension and compile on unity for windows 32bit or 64bit.

*Part 1

https://github.com/walidabazo/unity-used-SQLite-database

sdb.cs:

using System.Collections;
  using System.Collections.Generic;
  using UnityEngine;
  using Mono.Data.Sqlite;
  using System.Data;
  using System;
  public class insert : MonoBehaviour {
  private string conn, sqlQuery;
  IDbConnection dbconn;
  IDbCommand dbcmd;
  // Use this for initialization
  void Start () {
  conn = "URI=file:" + Application.dataPath + "/Plugins/Users.s3db"; //Path to database.
  //Deletvalue(6);
  //insertvalue("ahmedm", "ahmedm@gmail.com", "sss");
  Updatevalue("a","w@gamil.com","1st",1);
  readers();
  }
   
  private void insertvalue(string name, string email, string address)
  {
  using (dbconn = new SqliteConnection(conn))
  {
  dbconn.Open(); //Open connection to the database.
  dbcmd = dbconn.CreateCommand();
  sqlQuery = string.Format("insert into Usersinfo (Name, Email, Address) values (\"{0}\",\"{1}\",\"{2}\")",name,email,address);// table name
  dbcmd.CommandText = sqlQuery;
  dbcmd.ExecuteScalar();
  dbconn.Close();
  }
  }
  private void Deletvalue(int id)
  {
  using (dbconn = new SqliteConnection(conn))
  {
  dbconn.Open(); //Open connection to the database.
  dbcmd = dbconn.CreateCommand();
  sqlQuery = string.Format("Delete from Usersinfo WHERE ID=\"{0}\"", id);// table name
  dbcmd.CommandText = sqlQuery;
  dbcmd.ExecuteScalar();
  dbconn.Close();
  }
  }
   
   
  private void Updatevalue(string name, string email, string address,int id)
  {
  using (dbconn = new SqliteConnection(conn))
  {
   
  dbconn.Open(); //Open connection to the database.
  dbcmd = dbconn.CreateCommand();
  sqlQuery = string.Format("UPDATE Usersinfo set Name=\"{0}\", Email=\"{1}\", Address=\"{2}\" WHERE ID=\"{3}\" ", name, email, address, id);// table name
  dbcmd.CommandText = sqlQuery;
  dbcmd.ExecuteScalar();
  dbconn.Close();
  }
  }
   
   
  private void readers()
  {
  using (dbconn = new SqliteConnection(conn))
  {
  dbconn.Open(); //Open connection to the database.
  dbcmd = dbconn.CreateCommand();
  sqlQuery = "SELECT * " + "FROM Usersinfo";// table name
  dbcmd.CommandText = sqlQuery;
  IDataReader reader = dbcmd.ExecuteReader();
  while (reader.Read())
  {
  int id = reader.GetInt32(0);
  string name = reader.GetString(1);
  string Email = reader.GetString(2);
  string Phone = reader.GetString(3);
   
  Debug.Log("value= " + id + " name =" + name + " Eamil =" + Email + " Phone" + Phone);
  }
  reader.Close();
  reader = null;
  dbcmd.Dispose();
  dbcmd = null;
  dbconn.Close();
  dbconn = null;
  }
  }
   
  // Update is called once per frame
  void Update () {
   
  }
  }